home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / updateteamname.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  7KB  |  328 lines

  1. /* ***********************************************************************
  2.  
  3.   UPDATE TEAM NAME PROGRAM FOR FOOTBALL REXX SUITE
  4.   ------------------------------------------------
  5.                    Copyright  Mark Naughton 1999
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       050999   Created.
  12.  
  13. **************************************************************************
  14.  
  15. Procedure
  16. ---------
  17.  
  18. 1. Check files exist.
  19. 2. Read datafiles in one at a time into an array.
  20. 3. Search array for occurrences of 'team_srch' and when found overwrite
  21.    the old name with the new one.
  22. 4. If marker set, write data back to file.
  23. 5. Exit.
  24.  
  25. ************************************************************************** */
  26. PARSE ARG league_stuff
  27.  
  28. version      = 1
  29. input_file   = '.df'
  30. input2_file  = '.sf'
  31. input3_file  = '.sflearn'
  32. input4_file  = '.stats'
  33. sdlines.     = '???'
  34. separator    = '*'
  35. file1        = 0
  36. file2        = 0
  37. file3        = 0
  38. file4        = 0
  39.  
  40. parse var league_stuff league_file "*" team_srch "*" team_repl
  41. league_file = "Data/"strip(league_file)
  42.  
  43. if open(datafile,"Data/Football.locale",'r') then do
  44.    line = readln(datafile)
  45.    locdir = strip(line)
  46.    close(datafile)
  47. end
  48. else do
  49.    say
  50.    say "ERROR :    (UpdateTeamName)"
  51.    say
  52.    say "Cannot read 'Data/Football.locale' for the locale settings."
  53.    exit
  54. end
  55.  
  56. locdir = locdir"Exec/UpdateTeamName.data"
  57.  
  58. if open(datafile,"ENV:FootballRXPath",'r') then do
  59.    line = readln(datafile)
  60.    rxdir = strip(line)
  61.    close(datafile)
  62. end
  63. else
  64.    rxdir = "SYS:Rexxc/"
  65.  
  66. if exists(locdir) > 0 then do
  67.   address command rxdir'rx 'locdir
  68.   VarCount = getclip('VarCount')
  69.   do i = 1 to VarCount
  70.     interpret getclip('var.'i)
  71.   end
  72. end
  73. else do
  74.    say
  75.    say "ERROR :    (UpdateTeamName)"
  76.    say
  77.    say "Cannot find '"locdir"' to read locale settings."
  78.    exit
  79. end
  80.  
  81. team_srch = strip(team_srch)
  82. team_repl = strip(team_repl)
  83.  
  84. if exists(league_file || input_file) = 0  then do
  85.    say
  86.    say utn_error
  87.    say
  88.    say utn_one"'"league_file||input_file"'."
  89.    exit
  90. end
  91. if exists(league_file || input2_file) = 0 then do
  92.    say
  93.    say utn_error
  94.    say
  95.    say utn_one"'"league_file||input2_file"'."
  96.    exit
  97. end
  98.                 /* this will cause a non-started league to fail when updating */
  99. /*
  100. if exists(league_file || input3_file) = 0 then do
  101.    say
  102.    say utn_error
  103.    say
  104.    say utn_one"'"league_file||input3_file"'."
  105.    exit
  106. end
  107. */
  108. if exists(league_file || input4_file) = 0 then do
  109.    say
  110.    say utn_error
  111.    say
  112.    say utn_one"'"league_file||input4_file"'."
  113.    exit
  114. end
  115.  
  116. /* Read, Change and Write Back .df file */
  117.  
  118. sdcount = 0
  119. if open(datafile,league_file || input_file,'r') then do
  120.    do while ~eof(datafile)
  121.       line = readln(datafile)
  122.       line = strip(line)
  123.       sdcount         = sdcount + 1
  124.       sdlines.sdcount = line
  125.    end
  126.    close(datafile)
  127. end
  128. else do
  129.    say
  130.    say utn_error
  131.    say
  132.    say utn_two"'"league_file||input_file"'"utn_three
  133.    exit
  134. end
  135.  
  136. mkt = 0
  137. do i=1 to sdcount
  138.    if pos(separator,sdlines.i) = 0 then do
  139.       if team_srch == strip(sdlines.i) then do
  140.          sdlines.i = team_repl
  141.          mkt = 1
  142.          leave
  143.       end
  144.    end
  145. end
  146.  
  147. if mkt = 1 then do
  148.    if open(datafile3,league_file || input_file,'w') then do
  149.       do j=1 to sdcount
  150.          if sdlines.j~="" then writeln(datafile3,sdlines.j)
  151.       end
  152.       close(datafile3)
  153.    end
  154.    else do
  155.       say
  156.       say utn_error
  157.       say
  158.       say utn_two"'"league_file || input_file"'"utn_four
  159.       exit
  160.    end
  161.    file1 = 1
  162. end
  163.  
  164. /* Read, Change and Write Back .sf file */
  165.  
  166. sdcount = 0
  167. if open(datafile,league_file||input2_file,'r') then do
  168.    do while ~eof(datafile)
  169.       line = readln(datafile)
  170.       line = strip(line)
  171.       sdcount         = sdcount + 1
  172.       sdlines.sdcount = line
  173.    end
  174.    close(datafile)
  175. end
  176. else do
  177.    say
  178.    say utn_error
  179.    say
  180.    say utn_two"'"league_file||input2_file"'"utn_three
  181.    exit
  182. end
  183.  
  184. mkt = 0
  185. do i=1 to sdcount
  186.    if pos(separator,sdlines.i) = 0 then do
  187.       if pos(team_srch,sdlines.i) > 0 then do
  188.          t1 = strip(substr(sdlines.i,1,30))
  189.          t2 = strip(substr(sdlines.i,41,30))
  190.          if t1 == team_srch then sdlines.i = overlay(left(team_repl,30," "),sdlines.i,1,30)
  191.          if t2 == team_srch then sdlines.i = overlay(left(team_repl,30," "),sdlines.i,41,30)
  192.          mkt = 1
  193.       end
  194.    end
  195. end
  196.  
  197. if mkt = 1 then do
  198.    if open(datafile3,league_file || input2_file,'w') then do
  199.       do j=1 to sdcount
  200.          if sdlines.j~="" then writeln(datafile3,sdlines.j)
  201.       end
  202.       close(datafile3)
  203.    end
  204.    else do
  205.       say
  206.       say utn_error
  207.       say
  208.       say utn_two"'"league_file || input2_file"'"utn_four
  209.       exit
  210.    end
  211.    file2 = 1
  212. end
  213.  
  214. /* Read, Change and Write Back .sflearn file */
  215.  
  216. sdcount = 0
  217. if open(datafile,league_file||input3_file,'r') then do
  218.    do while ~eof(datafile)
  219.       line = readln(datafile)
  220.       line = strip(line)
  221.       sdcount         = sdcount + 1
  222.       sdlines.sdcount = line
  223.    end
  224.    close(datafile)
  225. end
  226. else do
  227.    say
  228.    say utn_error
  229.    say
  230.    say utn_two"'"league_file||input3_file"'"utn_three
  231.    exit
  232. end
  233.  
  234. mkt = 0
  235. do i=1 to sdcount
  236.    if pos(separator,sdlines.i) = 0 then do
  237.       if pos(team_srch,sdlines.i) > 0 then do
  238.          t1 = strip(substr(sdlines.i,1,30))
  239.          t2 = strip(substr(sdlines.i,41,30))
  240.          if t1 == team_srch then sdlines.i = overlay(left(team_repl,30," "),sdlines.i,1,30)
  241.          if t2 == team_srch then sdlines.i = overlay(left(team_repl,30," "),sdlines.i,41,30)
  242.          mkt = 1
  243.       end
  244.    end
  245. end
  246.  
  247. if mkt = 1 then do
  248.    if open(datafile3,league_file || input3_file,'w') then do
  249.       do j=1 to sdcount
  250.          if sdlines.j~="" then writeln(datafile3,sdlines.j)
  251.       end
  252.       close(datafile3)
  253.    end
  254.    else do
  255.       say
  256.       say utn_error
  257.       say
  258.       say utn_two"'"league_file || input3_file"'"utn_four
  259.       exit
  260.    end
  261.    file3 = 1
  262. end
  263.  
  264. /* Read, Change and Write Back .stats file */
  265.  
  266. sdcount = 0
  267. if open(datafile,league_file||input4_file,'r') then do
  268.    do while ~eof(datafile)
  269.       line = readln(datafile)
  270.       line = strip(line)
  271.       sdcount         = sdcount + 1
  272.       sdlines.sdcount = line
  273.    end
  274.    close(datafile)
  275. end
  276. else do
  277.    say
  278.    say utn_error
  279.    say
  280.    say utn_two"'"league_file||input4_file"'"utn_five
  281.    exit
  282. end
  283.  
  284. mkt = 0
  285. do i=1 to sdcount
  286.    if pos("*TEAM=",sdlines.i) > 0 then do
  287.       parse var sdlines.i "*TEAM=" lteam
  288.       lteam = strip(lteam)
  289.       if team_srch == lteam then do
  290.          sdlines.i = "*TEAM="team_repl
  291.          mkt = 1
  292.          leave
  293.       end
  294.    end
  295. end
  296.  
  297. if mkt = 1 then do
  298.    if open(datafile3,league_file || input4_file,'w') then do
  299.       do j=1 to sdcount
  300.          if sdlines.j~="" then writeln(datafile3,sdlines.j)
  301.       end
  302.       close(datafile3)
  303.    end
  304.    else do
  305.       say
  306.       say utn_error
  307.       say
  308.       say utn_two"'"league_file || input4_file"'"utn_four
  309.       exit
  310.    end
  311.    file4 = 1
  312. end
  313.  
  314. say
  315. say center(utn_t1,78)
  316. say "-----------------------------------------------------------------------------------------"
  317. say
  318. say utn_t2" '"team_srch"' "utn_t3" '"team_repl"'."
  319. say
  320. say utn_t4
  321. say
  322. if file1 = 1 then say "     '"league_file||input_file"'"
  323. if file2 = 1 then say "     '"league_file||input2_file"'"
  324. if file3 = 1 then say "     '"league_file||input3_file"'"
  325. if file4 = 1 then say "     '"league_file||input4_file"'"
  326. say
  327.  
  328. exit